package org.yuanzheng.wordcount

import java.net.URL

import org.apache.flink.api.scala.{DataSet, ExecutionEnvironment}

/**
 * @author yuanzheng
 * @date 2020/6/10-21:25
 */
object BatchWordCount {
  def main(args: Array[String]): Unit = {
    // 1.初始化批计算环境
    val environment: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    // 2.文件路径
    val url: URL = getClass.getResource("/words.txt")
    // 3.导入隐式转换
    import org.apache.flink.streaming.api.scala._
    // 4.读取文件
    val value: DataSet[String] = environment.readTextFile(url.getPath)
    // 5.处理和输出
    value.flatMap(_.split(" ")).map((_, 1)).groupBy(0).sum(1).print()
  }
}
